package com.hualan.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.domain.Heartmark;
import com.hualan.domain.Publicity;
import com.hualan.mapper.HeartmarkMapper;
import com.hualan.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HeartmarkService {
    @Autowired
    private HeartmarkMapper heartmarkMapper;

    //搜索全部信息
    public R selectAll(){
        return R.success(heartmarkMapper.selectAll());
    }

    //insert
    public R addHeartMark(Heartmark heartmark){
        return R.success(heartmarkMapper.insertSelective(heartmark));
    }



    public PageInfo<Heartmark> selAllByPage(int pageNum, int pageSize){
        int count = heartmarkMapper.getCount();
        PageHelper.startPage(pageNum,pageSize);
        List<Heartmark> list=heartmarkMapper.selectAll();
        PageInfo<Heartmark> pageInfo= new PageInfo<>(list);
        pageInfo.setTotal(count);
        return pageInfo;
    }
    public R updateById(Heartmark heartmark){
        return R.success(heartmarkMapper.updateByPrimaryKeySelective(heartmark));
    }
    public R delectById(int id){
        return R.success(heartmarkMapper.deleteByPrimaryKey((long)id));
    }

    public R queryAllCePing() {
        List<Heartmark> list = heartmarkMapper.queryCePingList();
        if (list == null) {
            return R.fail("查无此数据！");
        }
        return R.success(list);
    }

}
